class Corporativo < ActiveRecord::Base
  belongs_to :ejecutivo
  has_many :centros, :conditions => {:status_id => 1}
  
  validates_presence_of :nombre_comercial, :razon_social, :rfc, :calle, :num_exterior, :codigo_postal, :colonia, :ciudad, :on => :create
  validates_presence_of :estado_id, :on => :create
  
  validates_uniqueness_of :nombre_comercial, :on => :create
  
  validates_format_of :rfc, :with => /[A-Z]{3,4}[0-9]{6}(([A-Z]|[0-9]){3})/, :on => :create
  
  validates_length_of :nombre_comercial, :razon_social, :calle, :maximum => 40, :on => :create
  validates_length_of :rfc, :in => 12..13, :on => :create
  validates_length_of :codigo_postal, :is => 5, :on => :create
  validates_length_of :num_exterior, :num_interior, :maximum => 5, :on => :create
  
  validates_numericality_of :codigo_postal, :on => :create

  def domicilio
    "#{calle} #{num_exterior}/#{num_interior}, COL. #{colonia}, C.P. #{codigo_postal}, #{ciudad}"
    
  end

end
